home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / postscript.314 < prev    next >
Text File  |  1992-02-06  |  2KB  |  55 lines

  1. {\rtf0\ansi{\fonttbl\f1\fnil Times-Roman;\f2\fmodern Courier;\f0\fswiss Helvetica;}
  2. \paperw13040
  3. \paperh10800
  4. \margl120
  5. \margr120
  6. \pard\tx622\tx1245\tx1868\tx2490\tx3113\tx3736\tx4359\tx4981\tx5604\tx6227\f1\b0\i0\ul0\fs28 pswrap boolean postscript\
  7. \
  8. Q:  Boolean results from pswrap functions are wrong.  I use:\
  9. \
  10.  
  11. \f2     defineps foo ( | boolean *b)\
  12.          ...\
  13.     endps\
  14.  
  15. \f1 \
  16.     And later, in my ObjC code,\
  17. \
  18.  
  19. \f2     BOOL B;\
  20.     foo (&B);\
  21.  
  22. \f1 \
  23.     B contains 0 no matter what foo() returns. What's wrong?\
  24. \
  25. A:  The client library is fine; the real problem is type mismatch, which COULD have been detected by using the type-checking ability of the compiler.  In the pswrap-generated code, the boolean b is really an int.  The BOOL type of Objective-C, however, is an unsigned char.  Thus, if you use the boolean declaration at the pswrap end, you should use int in the C code.  The pswrap code would still look like this:\
  26. \
  27.  
  28. \f2     defineps foo (| boolean *b)\
  29.         ...\
  30.     endps\
  31.  
  32. \f1     \
  33. However, the ObjC code will look like this:\
  34. \
  35.  
  36. \f2     int B;\
  37.     foo (&B);\
  38.  
  39. \f1 \
  40. When passing booleans back and forth, remember that on the PostScript side a value of 0 will be translated into a PostScript boolean object  whose value is 
  41. \i false
  42. \i0 . Any other value will be translated to a PostScript boolean object whose value is 
  43. \i true
  44. \i0 .\
  45. \
  46. The above problem can be caught by using the "-a" flag to pswrap to generate ANSI prototypes and import the generated file.  By default, pswrap does not generate full prototypes and the above problem is missed at compile time. \
  47. \
  48. QA314\
  49. \
  50. Valid for 1.0\
  51. Valid for 2.0\
  52. \
  53.  
  54.  
  55.